﻿Imports System
Imports System.Collections.Generic
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Runtime.CompilerServices
Imports System.Windows.Forms
Imports System.Workflow.ComponentModel

Namespace System.Workflow.ComponentModel.Design
    Friend NotInheritable Class PreviewItemStrip
        ' Events
        Public Custom Event SelectionChanged As SelectionChangeEventHandler([Of] SelectionChangeEventArgs)

        ' Methods
        Public Sub New(ByVal parentDesigner As ActivityPreviewDesigner)
            If (parentDesigner Is Nothing) Then
                Throw New ArgumentNullException("parentDesigner")
            End If
            Me.parentDesigner = parentDesigner
            Me.items = New ItemList([Of] ItemInfo)(Me)
            AddHandler Me.items.ListChanging, New ItemListChangeEventHandler([Of] ItemInfo)(AddressOf Me.OnItemsChanging)
            AddHandler Me.items.ListChanged, New ItemListChangeEventHandler([Of] ItemInfo)(AddressOf Me.OnItemsChanged)
        End Sub

        Public Sub Draw(ByVal graphics As Graphics)
            Dim ambientTheme As AmbientTheme = WorkflowTheme.CurrentTheme.AmbientTheme
            Dim designerTheme As ActivityPreviewDesignerTheme = [TryCast](Me.parentDesigner.DesignerTheme,ActivityPreviewDesignerTheme)
            If (Not designerTheme Is Nothing) Then
                Dim stripRectangle As Rectangle = Me.StripRectangle
                Dim path As New GraphicsPath
                If (designerTheme.DesignerGeometry = DesignerGeometry.RoundedRectangle) Then
                    path.AddPath(ActivityDesignerPaint.GetRoundedRectanglePath(stripRectangle, 4), False)
                Else
                    path.AddRectangle(stripRectangle)
                End If
                path.CloseFigure
                graphics.FillPath(designerTheme.PreviewBackgroundBrush, path)
                graphics.DrawPath(designerTheme.PreviewBorderPen, path)
                path.Dispose
                Dim leftScrollImageUp As Image = ActivityPreviewDesignerTheme.LeftScrollImageUp
                Dim buttonBounds As Rectangle = Me.GetButtonBounds(ScrollButton.Left)
                If (Me.ActiveScrollButton = ScrollButton.Left) Then
                    leftScrollImageUp = ActivityPreviewDesignerTheme.LeftScrollImage
                    buttonBounds.Offset(1, 1)
                End If
                If (Not leftScrollImageUp Is Nothing) Then
                    ActivityDesignerPaint.DrawImage(graphics, leftScrollImageUp, buttonBounds, DesignerContentAlignment.Center)
                End If
                leftScrollImageUp = ActivityPreviewDesignerTheme.RightScrollImageUp
                buttonBounds = Me.GetButtonBounds(ScrollButton.Right)
                If (Me.ActiveScrollButton = ScrollButton.Right) Then
                    leftScrollImageUp = ActivityPreviewDesignerTheme.RightScrollImage
                    buttonBounds.Offset(1, 1)
                End If
                If (Not leftScrollImageUp Is Nothing) Then
                    ActivityDesignerPaint.DrawImage(graphics, leftScrollImageUp, buttonBounds, DesignerContentAlignment.Center)
                End If
                Dim itemMargin As Size = Me.ItemMargin
                Dim width As Integer = Math.Max(Math.Min(CInt((itemMargin.Width / 4)), CInt((itemMargin.Height / 2))), 1)
                Dim i As Integer = Me.scrollMarker
                Do While ((i < Me.items.Count) AndAlso (i < (Me.scrollMarker + Me.VisibleItemCount)))
                    Dim itemBounds As Rectangle = Me.GetItemBounds(Me.items.Item(i))
                    If Not itemBounds.IsEmpty Then
                        Dim path2 As New GraphicsPath
                        If (designerTheme.DesignerGeometry = DesignerGeometry.RoundedRectangle) Then
                            path2.AddPath(ActivityDesignerPaint.GetRoundedRectanglePath(itemBounds, 4), True)
                        Else
                            path2.AddRectangle(itemBounds)
                        End If
                        graphics.FillPath(designerTheme.PreviewForegroundBrush, path2)
                        graphics.DrawPath(designerTheme.PreviewBorderPen, path2)
                        path2.Dispose
                        Dim image As Image = Me.items.Item(i).Image
                        If (image Is Nothing) Then
                            Dim activity As Activity = [TryCast](Me.items.Item(i).UserData.Item(DesignerUserDataKeys.Activity),Activity)
                            Dim designer As ActivityDesigner = ActivityDesigner.GetDesigner(activity)
                            If (Not designer Is Nothing) Then
                                image = designer.Image
                            End If
                        End If
                        If (Not image Is Nothing) Then
                            Dim empty As Rectangle = Rectangle.Empty
                            empty.X = (itemBounds.Left + 2)
                            empty.Y = (itemBounds.Top + 2)
                            empty.Size = New Size((itemBounds.Width - 4), (itemBounds.Height - 4))
                            ActivityDesignerPaint.DrawImage(graphics, image, empty, DesignerContentAlignment.Center)
                        End If
                        If (i = Me.items.IndexOf(Me.ActiveItem)) Then
                            itemBounds.Inflate(width, width)
                            graphics.DrawRectangle(ambientTheme.SelectionForegroundPen, itemBounds)
                        End If
                    End If
                    i += 1
                Loop
                Dim dropTargets As Rectangle() = Me.DropTargets
                Dim activeDropTarget As Integer = Me.ActiveDropTarget
                If ((activeDropTarget >= 0) AndAlso (activeDropTarget < dropTargets.GetLength(0))) Then
                    dropTargets(activeDropTarget).Width = itemMargin.Width
                    graphics.DrawLine(ambientTheme.DropIndicatorPen, (dropTargets(activeDropTarget).Left + (dropTargets(activeDropTarget).Width / 2)), dropTargets(activeDropTarget).Top, (dropTargets(activeDropTarget).Left + (dropTargets(activeDropTarget).Width / 2)), dropTargets(activeDropTarget).Bottom)
                ElseIf ((Me.items.Count = 0) AndAlso (Me.helpText.Length > 0)) Then
                    stripRectangle.Inflate(-2, -2)
                    Dim textBrush As Brush = If((Me.ActiveDropTarget <> -1), ambientTheme.DropIndicatorBrush, designerTheme.ForegroundBrush)
                    ActivityDesignerPaint.DrawText(graphics, designerTheme.Font, Me.helpText, stripRectangle, StringAlignment.Center, WorkflowTheme.CurrentTheme.AmbientTheme.TextQuality, textBrush)
                End If
            End If
        End Sub

        Private Sub EnsureScrollMarker()
            If ((Not Me.ActiveItem Is Nothing) AndAlso (Me.VisibleItemCount <> 0)) Then
                Dim num As Integer = -1
                Dim index As Integer = Me.items.IndexOf(Me.ActiveItem)
                If (index >= 0) Then
                    num = If((index < Me.scrollMarker), index, If((index >= (Me.scrollMarker + Me.VisibleItemCount)), ((index - Me.VisibleItemCount) + 1), num))
                End If
                If ((Me.items.Count >= Me.VisibleItemCount) AndAlso ((Me.items.Count - Me.scrollMarker) < Me.VisibleItemCount)) Then
                    num = (Me.items.Count - Me.VisibleItemCount)
                End If
                If ((num >= 0) AndAlso (num <= Math.Max(((Me.items.Count - Me.VisibleItemCount) + 1), 0))) Then
                    Me.scrollMarker = num
                End If
                Me.Invalidate
            End If
        End Sub

        Private Function GetButtonBounds(ByVal scrollButton As ScrollButton) As Rectangle
            Dim leftScrollImage As Image = ActivityPreviewDesignerTheme.LeftScrollImage
            If ((scrollButton = ScrollButton.Up) OrElse (leftScrollImage Is Nothing)) Then
                Return Rectangle.Empty
            End If
            Dim size As Size = leftScrollImage.Size
            size.Height = Math.Min(size.Width, Math.Min(size.Height, Me.ItemSize.Height))
            size.Width = Math.Min(size.Width, size.Height)
            Dim num As Integer = If((scrollButton = ScrollButton.Left), Me.bounds.X, (Me.bounds.Right - size.Width))
            Dim empty As Rectangle = Rectangle.Empty
            empty.X = num
            empty.Y = ((Me.bounds.Y + (Me.bounds.Size.Height / 2)) - (size.Height / 2))
            empty.Size = size
            Return empty
        End Function

        Public Function GetItemBounds(ByVal itemInfo As ItemInfo) As Rectangle
            Dim index As Integer = Me.items.IndexOf(itemInfo)
            If (index < 0) Then
                Return Rectangle.Empty
            End If
            If ((index < Me.scrollMarker) OrElse (index >= (Me.scrollMarker + Me.VisibleItemCount))) Then
                Return Rectangle.Empty
            End If
            Dim stripRectangle As Rectangle = Me.StripRectangle
            Dim empty As Rectangle = Rectangle.Empty
            Dim itemMargin As Size = Me.ItemMargin
            Dim itemSize As Size = Me.ItemSize
            index = (index - Me.scrollMarker)
            empty.X = ((stripRectangle.Left + (index * itemSize.Width)) + ((index + 1) * itemMargin.Width))
            empty.Y = (stripRectangle.Top + itemMargin.Height)
            empty.Size = itemSize
            Return empty
        End Function

        Public Function HitTest(ByVal point As Point) As ItemInfo
            Dim i As Integer
            For i = Me.scrollMarker To Me.items.Count - 1
                If Me.GetItemBounds(Me.items.Item(i)).Contains(point) Then
                    Return Me.items.Item(i)
                End If
            Next i
            Return Nothing
        End Function

        Private Sub Invalidate()
            If ((Not Me.parentDesigner Is Nothing) AndAlso (Not Me.parentDesigner.Activity.Site Is Nothing)) Then
                Dim service As WorkflowView = [TryCast](Me.parentDesigner.Activity.Site.GetService(GetType(WorkflowView)),WorkflowView)
                If (Not service Is Nothing) Then
                    service.InvalidateLogicalRectangle(Me.bounds)
                End If
            End If
        End Sub

        Private Sub OnItemsChanged(ByVal sender As Object, ByVal e As ItemListChangeEventArgs([Of] ItemInfo))
            If ((e.Action = ItemListChangeAction.Add) AndAlso (e.AddedItems.Count > 0)) Then
                Me.ActiveItem = e.AddedItems.Item(0)
            End If
            If (e.Action = ItemListChangeAction.Remove) Then
                Me.EnsureScrollMarker
            End If
            Me.accessibilityObjects = Nothing
            Me.Invalidate
        End Sub

        Private Sub OnItemsChanging(ByVal sender As Object, ByVal e As ItemListChangeEventArgs([Of] ItemInfo))
            If (((e.Action = ItemListChangeAction.Remove) AndAlso (e.RemovedItems.Count > 0)) AndAlso (Me.ActiveItem Is e.RemovedItems.Item(0))) Then
                Dim index As Integer = Me.items.IndexOf(e.RemovedItems.Item(0))
                index = (index + If((index < (Me.items.Count - 1)), 1, -1))
                Me.ActiveItem = If(((index >= 0) AndAlso (index < Me.items.Count)), Me.items.Item(index), Nothing)
            End If
        End Sub

        Public Sub OnLayoutSize(ByVal graphics As Graphics)
            Dim designerTheme As ActivityPreviewDesignerTheme = [TryCast](Me.parentDesigner.DesignerTheme,ActivityPreviewDesignerTheme)
            Dim itemMargin As Size = Me.ItemMargin
            Dim itemSize As Size = Me.ItemSize
            Me.bounds.Width = (2 * WorkflowTheme.CurrentTheme.AmbientTheme.Margin.Width)
            Me.bounds.Width = (Me.bounds.Width + (itemSize.Width * If((Not designerTheme Is Nothing), designerTheme.PreviewItemCount, 0)))
            Me.bounds.Width = (Me.bounds.Width + (itemMargin.Width * (If((Not designerTheme Is Nothing), designerTheme.PreviewItemCount, 0) + 1)))
            Me.bounds.Width = (Me.bounds.Width + Me.GetButtonBounds(ScrollButton.Left).Size.Width)
            Me.bounds.Width = (Me.bounds.Width + Me.GetButtonBounds(ScrollButton.Right).Size.Width)
            Me.bounds.Height = (itemSize.Height + (2 * itemMargin.Height))
            Me.EnsureScrollMarker
        End Sub

        Public Sub OnMouseDown(ByVal e As MouseEventArgs)
            Dim pt As New Point(e.X, e.Y)
            Dim num As Integer = 0
            If Me.GetButtonBounds(ScrollButton.Left).Contains(pt) Then
                Me.ActiveScrollButton = ScrollButton.Left
                num = -1
            ElseIf Me.GetButtonBounds(ScrollButton.Right).Contains(pt) Then
                Me.ActiveScrollButton = ScrollButton.Right
                num = 1
            End If
            If ((num <> 0) AndAlso (Not Me.ActiveItem Is Nothing)) Then
                Dim num2 As Integer = (Me.items.IndexOf(Me.ActiveItem) + num)
                num2 = If((num2 >= Me.items.Count), 0, If((num2 < 0), (Me.items.Count - 1), num2))
                Me.ActiveItem = Me.items.Item(num2)
            End If
        End Sub

        Public Sub OnMouseLeave()
            Me.ActiveScrollButton = ScrollButton.Up
        End Sub

        Public Sub OnMouseUp(ByVal e As MouseEventArgs)
            Me.ActiveScrollButton = ScrollButton.Up
        End Sub


        ' Properties
        Public ReadOnly Property AccessibilityObjects As AccessibleObject()
            Get
                If (Me.accessibilityObjects Is Nothing) Then
                    Me.accessibilityObjects = New List([Of] ItemStripAccessibleObject)
                    Me.accessibilityObjects.Add(New ItemStripAccessibleObject(AccessibleObjectType.LeftScroll, Me))
                    Dim i As Integer = 0
                    Do While ((i < Me.VisibleItemCount) AndAlso ((Me.scrollMarker + i) < Me.Items.Count))
                        Me.accessibilityObjects.Add(New ItemStripAccessibleObject(AccessibleObjectType.Item, Me, i))
                        i += 1
                    Loop
                    Me.accessibilityObjects.Add(New ItemStripAccessibleObject(AccessibleObjectType.RightScroll, Me))
                End If
                Return Me.accessibilityObjects.ToArray
            End Get
        End Property

        Public Property ActiveDropTarget As Integer
            Get
                Return Me.activeDropTarget
            End Get
            Set(ByVal value As Integer)
                If (Me.activeDropTarget <> value) Then
                    Me.activeDropTarget = value
                    Me.Invalidate
                End If
            End Set
        End Property

        Public Property ActiveItem As ItemInfo
            Get
                Return Me.activeItem
            End Get
            Set(ByVal value As ItemInfo)
                If (Not Me.activeItem Is value) Then
                    Dim activeItem As ItemInfo = Me.activeItem
                    Me.activeItem = value
                    Me.EnsureScrollMarker
                    If (Not Me.SelectionChanged Is Nothing) Then
                        Me.SelectionChanged.Invoke(Me, New SelectionChangeEventArgs(activeItem, Me.activeItem))
                    End If
                End If
            End Set
        End Property

        Private Property ActiveScrollButton As ScrollButton
            Get
                Return Me.activeScrollButton
            End Get
            Set(ByVal value As ScrollButton)
                If (Me.activeScrollButton <> value) Then
                    Me.activeScrollButton = value
                    Me.Invalidate
                End If
            End Set
        End Property

        Public ReadOnly Property Bounds As Rectangle
            Get
                Return Me.bounds
            End Get
        End Property

        Public ReadOnly Property DropTargets As Rectangle()
            Get
                Dim itemMargin As Size = Me.ItemMargin
                Dim itemSize As Size = Me.ItemSize
                Dim stripRectangle As Rectangle = Me.StripRectangle
                Dim rectangleArray As Rectangle() = New Rectangle((Me.items.Count + 1)  - 1) {}
                Dim index As Integer = 0
                Dim num2 As Integer = (Math.Min((Me.items.Count - Me.scrollMarker), Me.VisibleItemCount) + 1)
                Dim i As Integer
                For i = 0 To num2 - 1
                    index = (i + Me.scrollMarker)
                    rectangleArray(index).X = (stripRectangle.Left + (i * (itemSize.Width + itemMargin.Width)))
                    rectangleArray(index).Y = (stripRectangle.Top + (itemMargin.Height / 2))
                    rectangleArray(index).Size = New Size(itemMargin.Width, (itemSize.Height + itemMargin.Height))
                Next i
                rectangleArray(index) = New Rectangle(rectangleArray(index).Left, rectangleArray(index).Top, (stripRectangle.Right - rectangleArray(index).Left), rectangleArray(index).Height)
                Return rectangleArray
            End Get
        End Property

        Public Property HelpText As String
            Get
                Return Me.helpText
            End Get
            Set(ByVal value As String)
                Me.helpText = value
                If ((Me.items.Count = 0) AndAlso (Not Me.parentDesigner.Activity Is Nothing)) Then
                    Me.Invalidate
                End If
            End Set
        End Property

        Private ReadOnly Property ItemMargin As Size
            Get
                Dim itemSize As Size = Me.ItemSize
                Return New Size((itemSize.Width / 2), (itemSize.Height / 4))
            End Get
        End Property

        Public ReadOnly Property Items As IList([Of] ItemInfo)
            Get
                Return Me.items
            End Get
        End Property

        Private ReadOnly Property ItemSize As Size
            Get
                Dim designerTheme As ActivityPreviewDesignerTheme = [TryCast](Me.parentDesigner.DesignerTheme,ActivityPreviewDesignerTheme)
                If (designerTheme Is Nothing) Then
                    Return Size.Empty
                End If
                Return designerTheme.PreviewItemSize
            End Get
        End Property

        Public Property Location As Point
            Get
                Return Me.bounds.Location
            End Get
            Set(ByVal value As Point)
                If (Me.bounds.Location <> value) Then
                    Me.bounds.Location = value
                End If
            End Set
        End Property

        Public ReadOnly Property Size As Size
            Get
                Return Me.bounds.Size
            End Get
        End Property

        Private ReadOnly Property StripRectangle As Rectangle
            Get
                Dim empty As Rectangle = Rectangle.Empty
                Dim buttonBounds As Rectangle = Me.GetButtonBounds(ScrollButton.Left)
                Dim rectangle3 As Rectangle = Me.GetButtonBounds(ScrollButton.Right)
                Dim margin As Size = WorkflowTheme.CurrentTheme.AmbientTheme.Margin
                empty.X = (buttonBounds.Right + margin.Width)
                empty.Y = Me.bounds.Y
                empty.Width = ((rectangle3.Left - margin.Width) - (buttonBounds.Right + margin.Width))
                empty.Height = Me.bounds.Height
                Return empty
            End Get
        End Property

        Private ReadOnly Property VisibleItemCount As Integer
            Get
                Dim designerTheme As ActivityPreviewDesignerTheme = [TryCast](Me.parentDesigner.DesignerTheme,ActivityPreviewDesignerTheme)
                If (designerTheme Is Nothing) Then
                    Return 1
                End If
                Return designerTheme.PreviewItemCount
            End Get
        End Property


        ' Fields
        Private accessibilityObjects As List([Of] ItemStripAccessibleObject)
        Private activeDropTarget As Integer = -1
        Private activeItem As ItemInfo
        Private activeScrollButton As ScrollButton
        Private bounds As Rectangle = Rectangle.Empty
        Private helpText As String = String.Empty
        Private items As ItemList([Of] ItemInfo)
        Private parentDesigner As ActivityPreviewDesigner
        Private scrollMarker As Integer

        ' Nested Types
        Private NotInheritable Class ItemStripAccessibleObject
            Inherits AccessibleObject
            ' Methods
            Friend Sub New(ByVal type As AccessibleObjectType, ByVal itemStrip As PreviewItemStrip)
                Me.itemIndex = -1
                Me.accessibleObjectType = type
                Me.itemStrip = itemStrip
            End Sub

            Friend Sub New(ByVal type As AccessibleObjectType, ByVal itemStrip As PreviewItemStrip, ByVal itemIndex As Integer)
                Me.itemIndex = -1
                Me.accessibleObjectType = type
                Me.itemStrip = itemStrip
                Me.itemIndex = itemIndex
            End Sub

            Public Overrides Sub DoDefaultAction()
                If (Me.accessibleObjectType = AccessibleObjectType.Item) Then
                    Dim associatedDesigner As ActivityDesigner = Me.AssociatedDesigner
                    If (Not associatedDesigner Is Nothing) Then
                        Dim service As ISelectionService = [TryCast](Me.GetService(GetType(ISelectionService)),ISelectionService)
                        If (Not service Is Nothing) Then
                            service.SetSelectedComponents(New Object() { associatedDesigner.Activity }, SelectionTypes.Replace)
                        End If
                    End If
                End If
            End Sub

            Private Function GetService(ByVal serviceType As Type) As Object
                If ((Me.itemStrip.parentDesigner.Activity Is Nothing) AndAlso (Me.itemStrip.parentDesigner.Activity.Site Is Nothing)) Then
                    Return Nothing
                End If
                Return Me.itemStrip.parentDesigner.Activity.Site.GetService(serviceType)
            End Function

            Public Overrides Function Navigate(ByVal navdir As AccessibleNavigation) As AccessibleObject
                If ((navdir = AccessibleNavigation.Left) OrElse (navdir = AccessibleNavigation.Right)) Then
                    Dim accessibilityObjects As AccessibleObject() = Me.itemStrip.AccessibilityObjects
                    Dim num As Integer = -1
                    If (Me.accessibleObjectType = AccessibleObjectType.LeftScroll) Then
                        num = 0
                    ElseIf (Me.accessibleObjectType = AccessibleObjectType.RightScroll) Then
                        num = (accessibilityObjects.Length - 1)
                    ElseIf (Me.accessibleObjectType = AccessibleObjectType.Item) Then
                        num = (Me.itemIndex + If((navdir = AccessibleNavigation.Left), -1, 1))
                    End If
                    num = Math.Max(Math.Min((accessibilityObjects.Length - 1), num), 0)
                    Return accessibilityObjects(num)
                End If
                If (navdir = AccessibleNavigation.Previous) Then
                    Return Me.itemStrip.parentDesigner.AccessibilityObject
                End If
                If (navdir <> AccessibleNavigation.Next) Then
                    Return MyBase.Navigate(navdir)
                End If
                Dim length As Integer = Me.itemStrip.AccessibilityObjects.Length
                If (Me.itemStrip.parentDesigner.AccessibilityObject.GetChildCount > length) Then
                    Return Me.itemStrip.parentDesigner.AccessibilityObject.GetChild(length)
                End If
                Return Me.itemStrip.parentDesigner.AccessibilityObject.Navigate(navdir)
            End Function

            Public Overrides Sub [Select](ByVal flags As AccessibleSelection)
                If (Me.accessibleObjectType = AccessibleObjectType.Item) Then
                    Dim service As ISelectionService = [TryCast](Me.GetService(GetType(ISelectionService)),ISelectionService)
                    Dim associatedDesigner As ActivityDesigner = Me.AssociatedDesigner
                    If ((Not service Is Nothing) AndAlso (Not associatedDesigner Is Nothing)) Then
                        If (((flags And AccessibleSelection.TakeFocus) > AccessibleSelection.None) OrElse ((flags And AccessibleSelection.TakeSelection) > AccessibleSelection.None)) Then
                            service.SetSelectedComponents(New Object() { associatedDesigner.Activity }, SelectionTypes.Replace)
                        ElseIf ((flags And AccessibleSelection.AddSelection) > AccessibleSelection.None) Then
                            service.SetSelectedComponents(New Object() { associatedDesigner.Activity }, SelectionTypes.Add)
                        ElseIf ((flags And AccessibleSelection.RemoveSelection) > AccessibleSelection.None) Then
                            service.SetSelectedComponents(New Object() { associatedDesigner.Activity }, SelectionTypes.Remove)
                        End If
                    End If
                Else
                    MyBase.Select(flags)
                End If
            End Sub


            ' Properties
            Private ReadOnly Property AssociatedDesigner As ActivityDesigner
                Get
                    If (Me.accessibleObjectType = AccessibleObjectType.Item) Then
                        Dim num As Integer = (Me.itemStrip.scrollMarker + Me.itemIndex)
                        Dim info As ItemInfo = If(((num >= 0) AndAlso (num < Me.itemStrip.Items.Count)), Me.itemStrip.Items.Item(num), Nothing)
                        If (Not info Is Nothing) Then
                            Return ActivityDesigner.GetDesigner([TryCast](info.UserData.Item(DesignerUserDataKeys.Activity),Activity))
                        End If
                    End If
                    Return Nothing
                End Get
            End Property

            Public Overrides ReadOnly Property Bounds As Rectangle
                Get
                    Dim empty As Rectangle = Rectangle.Empty
                    If (Me.accessibleObjectType = AccessibleObjectType.LeftScroll) Then
                        empty = Me.itemStrip.GetButtonBounds(ScrollButton.Left)
                    ElseIf (Me.accessibleObjectType = AccessibleObjectType.RightScroll) Then
                        empty = Me.itemStrip.GetButtonBounds(ScrollButton.Right)
                    ElseIf (Me.accessibleObjectType = AccessibleObjectType.Item) Then
                        Dim num As Integer = (Me.itemStrip.scrollMarker + Me.itemIndex)
                        empty = If(((num >= 0) AndAlso (num < Me.itemStrip.Items.Count)), Me.itemStrip.GetItemBounds(Me.itemStrip.Items.Item(num)), Rectangle.Empty)
                    End If
                    If Not empty.IsEmpty Then
                        Dim service As WorkflowView = [TryCast](Me.itemStrip.parentDesigner.Activity.Site.GetService(GetType(WorkflowView)),WorkflowView)
                        If (Not service Is Nothing) Then
                            empty = New Rectangle(service.LogicalPointToScreen(empty.Location), service.LogicalSizeToClient(empty.Size))
                        End If
                    End If
                    Return empty
                End Get
            End Property

            Public Overrides ReadOnly Property DefaultAction As String
                Get
                    Return DR.GetString("AccessibleAction", New Object(0  - 1) {})
                End Get
            End Property

            Public Overrides ReadOnly Property Description As String
                Get
                    Dim str As String = String.Empty
                    If (Me.accessibleObjectType = AccessibleObjectType.LeftScroll) Then
                        Return DR.GetString("LeftScrollButtonAccessibleDescription", New Object(0  - 1) {})
                    End If
                    If (Me.accessibleObjectType = AccessibleObjectType.RightScroll) Then
                        Return DR.GetString("RightScrollButtonAccessibleDescription", New Object(0  - 1) {})
                    End If
                    If (Me.accessibleObjectType = AccessibleObjectType.Item) Then
                        Dim associatedDesigner As ActivityDesigner = Me.AssociatedDesigner
                        If (Not associatedDesigner Is Nothing) Then
                            str = DR.GetString("ActivityDesignerAccessibleDescription", New Object() { associatedDesigner.Activity.GetType.Name })
                        End If
                    End If
                    Return str
                End Get
            End Property

            Public Overrides ReadOnly Property Help As String
                Get
                    Dim str As String = String.Empty
                    If (Me.accessibleObjectType = AccessibleObjectType.LeftScroll) Then
                        Return DR.GetString("LeftScrollButtonAccessibleHelp", New Object(0  - 1) {})
                    End If
                    If (Me.accessibleObjectType = AccessibleObjectType.RightScroll) Then
                        Return DR.GetString("RightScrollButtonAccessibleHelp", New Object(0  - 1) {})
                    End If
                    If (Me.accessibleObjectType = AccessibleObjectType.Item) Then
                        Dim associatedDesigner As ActivityDesigner = Me.AssociatedDesigner
                        If (Not associatedDesigner Is Nothing) Then
                            str = DR.GetString("ActivityDesignerAccessibleHelp", New Object() { associatedDesigner.Activity.GetType.Name })
                        End If
                    End If
                    Return str
                End Get
            End Property

            Public Overrides Property Name As String
                Get
                    Dim str As String = String.Empty
                    If (Me.accessibleObjectType = AccessibleObjectType.LeftScroll) Then
                        Return DR.GetString("LeftScrollButtonName", New Object(0  - 1) {})
                    End If
                    If (Me.accessibleObjectType = AccessibleObjectType.RightScroll) Then
                        Return DR.GetString("RightScrollButtonName", New Object(0  - 1) {})
                    End If
                    If (Me.accessibleObjectType = AccessibleObjectType.Item) Then
                        Dim associatedDesigner As ActivityDesigner = Me.AssociatedDesigner
                        If (Not associatedDesigner Is Nothing) Then
                            Dim activity As Activity = associatedDesigner.Activity
                            str = If((Not activity Is Nothing), activity.QualifiedName, MyBase.Name)
                        End If
                    End If
                    Return str
                End Get
                Set(ByVal value As String)
                End Set
            End Property

            Public Overrides ReadOnly Property Parent As AccessibleObject
                Get
                    Return Me.itemStrip.parentDesigner.AccessibilityObject
                End Get
            End Property

            Public Overrides ReadOnly Property Role As AccessibleRole
                Get
                    Return AccessibleRole.Diagram
                End Get
            End Property

            Public Overrides ReadOnly Property State As AccessibleStates
                Get
                    Dim none As AccessibleStates = AccessibleStates.None
                    If (Me.accessibleObjectType = AccessibleObjectType.Item) Then
                        Dim associatedDesigner As ActivityDesigner = Me.AssociatedDesigner
                        If (TypeOf Me.GetService(GetType(ISelectionService)) Is ISelectionService AndAlso (Not associatedDesigner Is Nothing)) Then
                            none = If(associatedDesigner.IsSelected, AccessibleStates.Selected, AccessibleStates.Selectable)
                            none = (none Or AccessibleStates.MultiSelectable)
                            none = (none Or If(associatedDesigner.IsLocked, &H40, &H40000))
                            none = (none Or If(associatedDesigner.IsPrimarySelection, 4, &H100000))
                        End If
                    End If
                    Return none
                End Get
            End Property


            ' Fields
            Private accessibleObjectType As AccessibleObjectType
            Private itemIndex As Integer
            Private itemStrip As PreviewItemStrip

            ' Nested Types
            Friend Enum AccessibleObjectType
                ' Fields
                Item = 2
                LeftScroll = 1
                RightScroll = 3
            End Enum
        End Class
    End Class
End Namespace

